<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 手写instanceof */
    function Person() {
      
    }
    const p = new Person()
    console.log(p instanceof Person) // true
    console.log(p instanceof Object) // true
    console.log(p instanceof Function) // false


    /* 
    Type.prototype是为obj原型链上的某个原型对象
    */
    function myInstanceOf(obj, Type) {
      let objProto = obj.__proto__
      while(objProto) { // 只要还有原型对象, 就继续判断查找
        // Type的prootype是否指向的就是原型对象
        if (objProto===Type.prototype) return true
        // 取出下一个原型对象
        objProto = objProto.__proto__
      }
      return false
    }

    console.log(myInstanceOf(p, Person))
    console.log(myInstanceOf(p, Object))
    console.log(myInstanceOf(p, Function))





  </script>
</body>
</html>